package cn.xgj.sfzy.controller;

import cn.xgj.sfzy.entity.Psychology;
import cn.xgj.sfzy.service.PsychologyService;
import cn.xgj.sfzy.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PsychologyContoeller
 * @Description TODO
 * @Author 李政阳
 * @Date 2024年10月24日 10:03
 * @Version 1.0
 */
@RestController
@RequestMapping("/psychology")
public class PsychologyController {

    @Autowired
    private PsychologyService service;

    @PostMapping
    public Result add(@RequestBody Psychology psychology){
        int i = service.add(psychology);
        if (i==0){
            return Result.error("添加失败");
        }else {
            return Result.success("添加成功");
        }
    }
    @DeleteMapping("/{psychologyId}")
    public Result delete(@PathVariable(value = "psychologyId") Integer id){
        int i = service.delete(id);
        if (i==0){
            return Result.error("添加失败");
        }else {
            return Result.success("添加成功");
        }
    }
    @PutMapping
    public Result update(@RequestBody Psychology psychology){
        int i = service.update(psychology);
        if (i==0){
            return Result.error("添加失败");
        }else {
            return Result.success("添加成功");
        }
    }
    @GetMapping
    public Result findAll(
            @RequestParam(required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(required = false,defaultValue = "2") Integer pageSize,
            Psychology psychology){
        PageInfo<Psychology> info = service.findByPage(pageNum, pageSize, psychology);
        return Result.success(info);
    }



}
